package com.guguskins.back.common.security.entity;


import com.guguskins.back.entity.GuAdminUser;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.util.ObjectUtils;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

@Data
public class GuUserSrcurity implements UserDetails {
    private transient GuAdminUser adminUser;
    private List<String> jurisdictionList;
    public GuUserSrcurity(GuAdminUser guAdmin){
      if(guAdmin!=null){
          this.adminUser=guAdmin;
      }
    }
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        Collection<GrantedAuthority> authorities = new ArrayList<>();
        for(String jurisdiction : jurisdictionList) {
            if(ObjectUtils.isEmpty(jurisdiction)) {continue;
            }
            SimpleGrantedAuthority authority = new SimpleGrantedAuthority(jurisdiction);
            authorities.add(authority);
        }

        return authorities;
    }

    @Override
    public String getPassword() {
        return adminUser.getPassword();
    }

    @Override
    public String getUsername() {
        return adminUser.getPassword();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
